﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MongoDB.Bson;
using MongoDB.Bson.IO;
using MongoDB.Driver;
using MongoDB.Driver.Builders;
using lo = sqCore.sqLogger;
using Newtonsoft.Json;
using System.Xml;

using JsonPrettyPrinterPlus;

namespace sqCore
{
    public static class sqHelpper
    {
        public enum NextType { before, after };
        public enum MongoCommand { insert, update, remove };
        public enum SortType { Descending, Ascending };
        public enum DBType { MSSQL, MySQL, SQLite, Oracle, Mongo };
        

        public static DBType formatToDBType(string typeName)
        {
            if (typeName.ToLower() == "oracle")
                return DBType.Oracle;
            else if (typeName.ToLower() == "mongo" || typeName.ToLower() == "mongodb")
                return DBType.Mongo;
            else
                return DBType.MSSQL;               
        }

        public static XmlDocument FormatJsonToXML(string json)
        {
            return (XmlDocument)JsonConvert.DeserializeXmlNode(json);
        }

        public static string FormatXMLToJson(XmlDocument xml)
        {
            return JsonConvert.SerializeXmlNode(xml);           
        }

        public static string GetTaskJsonPreaty(sqTask Task)
        {
            string json=Task.ToJson<sqTask>();
            return BeautifyJson(json);
        }
       
        public static string BeautifyJson(string json)
        {
            var jpp = new JsonPrettyPrinter(new JsonPrettyPrinterPlus.JsonPrettyPrinterInternals.JsonPPStrategyContext());
            return jpp.PrettyPrint(json);
        }
                
    }
}
